package com.qingcheng.init;

import com.qingcheng.service.goods.CategoryService;
import com.qingcheng.service.goods.SkuService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//实现InitializingBean接口的类会在项目启动时自动调用
@Component
public class Init implements InitializingBean {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private SkuService skuService;

    //在项目运行时就执行该方法
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("------缓存预热-------");
        categoryService.saveCategoryTreeToRedis();
        skuService.saveAllPriceToRedis();
        //添加到索引库
        //skuService.importSkuListToEs();
    }
}
